package com.thf.controller;

import com.alibaba.fastjson.JSON;
import com.thf.model.PageModel;
import com.thf.model.ResultData;
import com.thf.service.UserService;
import com.thf.util.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@Controller
public class UserFindAllController {

    @Autowired
    private UserService userService ;

    @RequestMapping("/back/user/get")
    @ResponseBody
    public String userFindAll(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResultData result = null ;
        String startPage = req.getParameter("startPage");
        String pageSize = req.getParameter("pageSize");
        PageModel pageMode = new PageModel(Tool.curPageToInt(startPage), Tool.pageSizeToInt(pageSize));

           String val = req.getParameter("val");
           Map map = JSON.parseObject(val,Map.class);
           result = userService.userFind(pageMode,map);

//       反馈给前端--返回值
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("result", result);
        String resJson = JSON.toJSONString(result);
        return  resJson ;
    }
}
